package smartclass.adapter;

import java.util.ArrayList;

import smartclass.entity.StudentInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremyfeinstein.slidingmenu.example.R;

public class StudentAdapter extends ArrayAdapter<StudentInfo> {

	private Context context;
	private int resource;
	private ArrayList<StudentInfo> arrayStudent;

	public StudentAdapter(Context context, int resource,
			ArrayList<StudentInfo> arrayStudent) {
		super(context, resource, arrayStudent);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resource = resource;
		this.arrayStudent = arrayStudent;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(context);
		if (convertView == null) {
			convertView = inflater.inflate(resource, null);
		}
		ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon);
		StudentInfo student = arrayStudent.get(position);
		if (student.getGender().equals("male")) {
			icon.setImageResource(R.drawable.user_male);
		} else {
			icon.setImageResource(R.drawable.user_female);
		}
		TextView title = (TextView) convertView.findViewById(R.id.row_title);
		title.setText(student.getName());

		return convertView;
	}

}